package com.lh.serverforwebrtc.controller;

import com.alibaba.fastjson.JSON;
import com.lh.serverforwebrtc.bean.RespBean;
import com.lh.serverforwebrtc.service.SecurityCodeService;
import com.lh.serverforwebrtc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@Api(tags = "LoginController")
@RestController
@RequestMapping("login")
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private SecurityCodeService securityCodeService;

    /**
     * 返回6位数验证码
     * @return
     */
    @ApiOperation(value = "登录返回验证码")
    @GetMapping("code")
    public RespBean securityCode(@RequestParam("userPhone")String userPhone){
        return  userService.getUserByPhone(Long.valueOf(userPhone));
    }

    @ApiOperation(value = "登录接口")
    @PostMapping("login")
    public RespBean login(@RequestParam("userPhone")String userPhone,@RequestParam("code")String code){
        return securityCodeService.verifyPhone(Long.valueOf(userPhone),Integer.valueOf(code));
    }

}
